/********************************************************************************************
 * Copyright 2011, zhaosting <zhaosting@gmail.com>
 *
 * This file is part of QPcxPlugIn.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 *******************************************************************************************/

#ifndef QPCXHANDLER_H
#define QPCXHANDLER_H

#include <QImageIOHandler>
#include <QtGui>

typedef struct tagPCXFILEHEADER
{
    quint8	Manufacturer;       //总为0x0a,pcx文件标志
    quint8	Version;            //版本号，表示有哪个版本的PC Paintbrush软件生成
    quint8	Encoding;           //编码方式，总为1，表示采用同值长度编码
    quint8	BitsPerPixel;       //每像素所占位数
    quint16	XMin,YMin;          //左上角座标
    quint16	XMax,YMax;          //右下角座标
    quint16	XRes,YRes;          //所使用分辨率
    quint8	Palette[48];        //色盘，只对16色文件
    quint8	Reserved;           //保留
    quint8	ColorPlanes;        //颜色的位平面数;
    quint16	BytesPerLine;       //解码后每行的字节数
    quint16     PaletteType;        //色盘类型，1，灰度，2彩色
    quint8	Filler[58];
} PCXFILEHEADER;

typedef struct tagPCXPALETTE
{
    quint8 rgbRed;
    quint8 rgbGreen;
    quint8 rgbBlue;
}PCXPALETTE;


class QPcxHandler : public QImageIOHandler
{
public:
    QPcxHandler();
    bool canRead() const;
    bool read(QImage *image);
    bool write(const QImage & image);
private:
    PCXFILEHEADER   head;
    QVector <QRgb>  rgbtab;
    QByteArray      data;
};

#endif // QPCXHANDLER_H
